package leetcode.editor.cn.q1_300.q50;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author qidi
 * @date 2021-12-20 11:39:17
 */
class Q0078_Subsets {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        List<List<Integer>> result = new ArrayList<>();
        LinkedList<Integer> cur = new LinkedList<>();

        public List<List<Integer>> subsets(int[] nums) {
            for (int size = 0; size <= nums.length; size++) {
                process(nums, size, 0);
            }

            return result;
        }

        private void process(int[] nums, int size, int startIndex) {
            if (cur.size() == size) {
                result.add(new ArrayList<>(cur));
                return;
            }

            for (int i = startIndex; i < nums.length - (size - cur.size()) + 1; i++) {
                cur.add(nums[i]);
                process(nums, size, i + 1);
                cur.removeLast();
            }
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0078_Subsets().new Solution();
        System.out.println(solution.subsets(new int[]{1, 2, 3}));
        solution.result.clear();
        System.out.println(solution.subsets(new int[]{0}));
        solution.result.clear();
        System.out.println(solution.subsets(new int[]{1, 2}));
        solution.result.clear();
        System.out.println(solution.subsets(new int[]{1, 2, 3, 4}));
    }
}